function selectPictures() {
    window.imagePicker.getPictures(
        function (results) {
            if (results.length <= 0) {
                return;
            }
            var src = "";
            for (var i = 0; i < results.length; i++) {
                src += "<img src='https://localhost" + results[i] + "' width='100%' />"
            }
            document.getElementById("imgInfo").innerHTML = src;
        }, function (error) {
            console.log('Error: ' + error);
        }, {
            maximumImagesCount: 9,
            width: 800
        }
    );
}

function selectPictures2() {
    ImagePicker.getPictures(
        function (results) {
            if (results.length <= 0) {
                return;
            }
            var src = "";
            for (var i = 0; i < results.length; i++) {
                src += "<img src='https://localhost" + results[i] + "' width='100%' />"
            }
            document.getElementById("imgInfo").innerHTML = src;
        }, function (error) {
        console.log('Error: ' + error);
    }, {
        maximumImagesCount: 9,
        width: 800
    }
    );
}

function getMedias() {
    var args = {
        'selectMode': 100, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 40 //default 40 (Optional)
    };

    MediaPicker.getMedias(args, function(medias) {
        //medias [{mediaType: "image", path:'/storage/emulated/0/DCIM/Camera/2017.jpg', uri:"android retrun uri,ios retrun URL" size: 21993}]
        var src = "";
        for (var i = 0; i < medias.length; i++) {
            src += "<img src='https://app" + medias[i].path + "' width='100%' />"
        }
        console.log(src);
        document.getElementById("imgInfo").innerHTML = src;
        //getThumbnail(medias);
    }, function(e) { console.log(e) })
}

function getMediasVod() {
    var args = {
        'selectMode': 102, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 1 //default 40 (Optional)
    };

    MediaPicker.getMedias(args, function(medias) {
        //medias [{mediaType: "image", path:'/storage/emulated/0/DCIM/Camera/2017.jpg', uri:"android retrun uri,ios retrun URL" size: 21993}]
        if(medias.length > 0) {
            fileName = "https://app"+medias[0].path;
            var player = new Aliplayer({
                id: "vodId2", // 容器id
                source: fileName, // 视频url 支持互联网可直接访问的视频地址
                autoplay: false, // 自动播放
                width: "100%", // 播放器宽度
                height: "200px", // 播放器高度
                showBarTime: "2000",
                showBuffer: true,
                playsinline: true,
                preload: true,
                "controlBarVisibility": "click",
                skinLayout: [{
                    "name": "bigPlayButton",
                    "align": "cc",
                    "x": 0,
                    "y": 0
                }, { "name": "H5Loading", "align": "cc" }, {
                    "align": "blabs",
                    "x": 0,
                    "y": 0,
                    "name": "controlBar",
                    "children": [{
                        "align": "tlabs",
                        "x": 0,
                        "y": 0,
                        "name": "progress"
                    }, {
                        "align": "tl",
                        "x": 15,
                        "y": 26,
                        "name": "playButton"
                    }, {
                        "align": "tl",
                        "x": 10,
                        "y": 24,
                        "name": "timeDisplay"
                    }, {
                        "align": "tr",
                        "x": 20,
                        "y": 25,
                        "name": "fullScreenButton"
                    }, {
                        "align": "tr",
                        "x": 20,
                        "y": 25,
                        "name": "setButton"
                    }, {
                        "align": "tr",
                        "x": 20,
                        "y": 23,
                        "name": "streamButton"
                    }, {
                        "align": "tr",
                        "x": 20,
                        "y": 25,
                        "name": "volume"
                    }]
                }]
            });

            player.on("play", function () {
                //监听播放
                global_play = this;
            });

            player.on("requestFullScreen", function () {
                //全屏播放监听
            });

            player.on("cancelFullScreen", function () {
                //取消全屏播放
            });
            player.play();
        }

        //getThumbnail(medias);
    }, function(e) { console.log(e) })
}

function getMediasMix() {
    var args = {
        'selectMode': 101, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 40 //default 40 (Optional)
    };

    MediaPicker.getMedias(args, function(medias) {
        //medias [{mediaType: "image", path:'/storage/emulated/0/DCIM/Camera/2017.jpg', uri:"android retrun uri,ios retrun URL" size: 21993}]
        document.getElementById("imgVideoInfo").innerHTML = JSON.stringify(medias);
        //getThumbnail(medias);
    }, function(e) { console.log(e) })
}

function extractThumbnail() {
    var args = {
        'selectMode': 101, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 1 //default 40 (Optional)
    };
    MediaPicker.getMedias(args, function(medias) {
        //medias [{mediaType: "image", path:'/storage/emulated/0/DCIM/Camera/2017.jpg', uri:"android retrun uri,ios retrun URL" size: 21993}]
        if(medias.length > 0) {
            MediaPicker.extractThumbnail(medias[0], function(data) {
                document.getElementById("thumbnailInfo").src = 'data:image/jpeg;base64,' + data.thumbnailBase64;
            }, function(e) { console.log(e) });
        }
    }, function(e) { console.log(e) })
}

function compressImage() {
    var args = {
        'selectMode': 100, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 1 //default 40 (Optional)
    };
    MediaPicker.getMedias(args, function(medias) {
        //medias [{mediaType: "image", path:'/storage/emulated/0/DCIM/Camera/2017.jpg', uri:"android retrun uri,ios retrun URL" size: 21993}]
        if(medias.length > 0) {
            medias[0].quality = 50;
            MediaPicker.compressImage(medias[0], function(data) {
                document.getElementById("compressInfo").src = "https://localhost"+data.path;
            }, function(e) { console.log(e) });
        }
    }, function(e) { console.log(e) })
}

function takePhoto() {
    var cameraOptions={ quality: 25,mediaType: Camera.MediaType.PICTURE };//see cordova camera docs
    MediaPicker.takePhoto(function(media) {
        document.getElementById("takePhotoInfo").src = "https://localhost"+media.path;
    }, function(e) { console.log(e) }, cameraOptions);
}

function takeVideo() {
    var cameraOptions={ quality: 25,mediaType: Camera.MediaType.VIDEO };//see cordova camera docs
    MediaPicker.takePhoto(function(media) {
        fileName = "https://localhost"+media.path;
        var player = new Aliplayer({
            id: "vodId1", // 容器id
            source: fileName, // 视频url 支持互联网可直接访问的视频地址
            autoplay: false, // 自动播放
            width: "100%", // 播放器宽度
            height: "200px", // 播放器高度
            showBarTime: "2000",
            showBuffer: true,
            playsinline: true,
            preload: true,
            "controlBarVisibility": "click",
            skinLayout: [{
                "name": "bigPlayButton",
                "align": "cc",
                "x": 0,
                "y": 0
            }, { "name": "H5Loading", "align": "cc" }, {
                "align": "blabs",
                "x": 0,
                "y": 0,
                "name": "controlBar",
                "children": [{
                    "align": "tlabs",
                    "x": 0,
                    "y": 0,
                    "name": "progress"
                }, {
                    "align": "tl",
                    "x": 15,
                    "y": 26,
                    "name": "playButton"
                }, {
                    "align": "tl",
                    "x": 10,
                    "y": 24,
                    "name": "timeDisplay"
                }, {
                    "align": "tr",
                    "x": 20,
                    "y": 25,
                    "name": "fullScreenButton"
                }, {
                    "align": "tr",
                    "x": 20,
                    "y": 25,
                    "name": "setButton"
                }, {
                    "align": "tr",
                    "x": 20,
                    "y": 23,
                    "name": "streamButton"
                }, {
                    "align": "tr",
                    "x": 20,
                    "y": 25,
                    "name": "volume"
                }]
            }]
        });

        player.on("play", function () {
            //监听播放
            global_play = this;
        });

        player.on("requestFullScreen", function () {
            //全屏播放监听
        });

        player.on("cancelFullScreen", function () {
            //取消全屏播放
        });
        player.play();

    }, function(e) { console.log(e) }, cameraOptions);
}

function getImage() {
    var cameraOptions={ quality: 25,mediaType: Camera.MediaType.PICTURE };//see cordova camera docs
    var args = {
        'selectMode': 100, //101=picker image and video , 100=image , 102=video
        'maxSelectCount': 40 //default 40 (Optional)
    };

    MediaPicker.getMedias(args, function(medias) {
        if(medias.length > 0) {
            MediaPicker.getExifForKey(medias[0].uri, "size", function (info) {
                document.getElementById("imgOpt").innerHTML = "size:"+info;
            }, function (error) {

            })
        }
    }, function(e) { console.log(e) }, cameraOptions);
}
